package com.sgb.kjwl.view.ui.adapter.category;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.swgk.core.view.entity.MenuEntity;
import com.swgk.core.recyclerview.secondary.DescHolder;
import com.swgk.core.recyclerview.secondary.HeaderHolder;
import com.swgk.core.recyclerview.secondary.SectionedRecyclerViewAdapter;

import java.util.List;

public class CategoryLeaseRightAdapter extends SectionedRecyclerViewAdapter<MenuEntity, MenuEntity, HeaderHolder, DescHolder, RecyclerView.ViewHolder> {

    private Context mContext;

    public CategoryLeaseRightAdapter(Context context, List<MenuEntity> datas) {
        super(context, R.layout.item_category_lease_right_header, R.layout.item_category_lease_right_desc, datas);
        this.mContext = context;
    }

    @Override
    protected void onBindSectionHeaderViewHolder(HeaderHolder holder, int section, MenuEntity secondaryEntity) {
        holder.setBinding(BR.viewModel, secondaryEntity);
        RelativeLayout relative = holder.itemView.findViewById(R.id.rl_name);
        ViewGroup.LayoutParams params = relative.getLayoutParams();
        if (!TextUtils.isEmpty(secondaryEntity.getName())) {
            params.height = mContext.getResources().getDimensionPixelOffset(R.dimen.dp40);
        } else {
            params.height = mContext.getResources().getDimensionPixelOffset(R.dimen.dp15);
        }
        relative.setLayoutParams(params);
    }

    @Override
    protected void onBindSectionFooterViewHolder(RecyclerView.ViewHolder holder, int section) {

    }

    /**
     * @param holder
     * @param section
     * @param position
     * @param entity
     */
    @Override
    protected void onBindItemViewHolder(DescHolder holder, int section, int position, MenuEntity entity) {
        holder.setBinding(BR.viewModel, entity);
    }

}